import Request from "@/common/utils/request/index";
import {
  RepairCalculatePriceDto,
  CreateRepairOrderDto,
  GetRepairDetailDTO,
} from "@/types/model/repair/dtos/repair.dto";

enum Api {
  GetRepairOrderList = "/jeecgboot/posRepair/list",
  CalculatePrice = "/jeecgboot/posRepair/calculatePrice",
  CreateRepairOrder = "/jeecgboot/posRepair/createRepairOrder",
  UpdateRepairSalesItems = "/jeecgboot/posRepair/updateRepairSalesItems",
  GetOrderDetail = "/jeecgboot/posRepair/orderDetail",
  ChangeRepairStatus = "/jeecgboot/posRepair/changeRepairStatus",
  UpdateCheckResult = "/jeecgboot/posRepair/updateCheckResult",
  UpdateCheckResultBatch = "/jeecgboot/posRepair/updateCheckResultBatch",
  UpdateRepairVariant = "/jeecgboot/posRepair/updateRepairVariant",
  UpdatePin = "/jeecgboot/posRepair/updatePin",
  UpdateSn = "/jeecgboot/posRepair/updateSn",
  AddRepairParts = "/jeecgboot/posRepair/addRepairParts",
  UpdateRepairParts = "/jeecgboot/posRepair/updateRepairParts",
  RemoveRepairParts = "/jeecgboot/posRepair/removeRepairParts",
}

export const getRepairOrderList = (params: any) => {
  return Request.getInstance().send({
    url: Api.GetRepairOrderList,
    method: "GET",
    params,
  });
};

export const calculatePrice = (params: RepairCalculatePriceDto) => {
  return Request.getInstance().send<number>({
    url: Api.CalculatePrice,
    method: "POST",
    data: params,
  });
};

export const createRepairOrder = (params: CreateRepairOrderDto) => {
  return Request.getInstance().send({
    url: Api.CreateRepairOrder,
    method: "POST",
    data: params,
  });
};

export const updateRepairSalesItems = (params: any) => {
  return Request.getInstance().send({
    url: Api.UpdateRepairSalesItems,
    method: "POST",
    data: params,
  });
};

export const getOrderDetail = (params: GetRepairDetailDTO) => {
  return Request.getInstance().send({
    url: Api.GetOrderDetail,
    method: "GET",
    params,
  });
};

export const changeRepairStatus = (params: { id: string; status: string }) => {
  return Request.getInstance().send({
    url: Api.ChangeRepairStatus,
    method: "POST",
    data: params,
  });
};

export const updateCheckResult = (params: { id: string; result: string }) => {
  return Request.getInstance().send({
    url: Api.UpdateCheckResult,
    method: "POST",
    data: params,
  });
};

export const updateCheckResultBatch = (params: {
  salesId: string;
  checkedIds?: string[];
  uncheckedIds?: string[];
}) => {
  return Request.getInstance().send({
    url: Api.UpdateCheckResultBatch,
    method: "POST",
    data: params,
  });
};

export const updateRepairVariant = (params: {
  id: string;
  variantId: string;
}) => {
  return Request.getInstance().send({
    url: Api.UpdateRepairVariant,
    method: "POST",
    data: params,
  });
};

export const updatePin = (params: { id: string; pin: string }) => {
  return Request.getInstance().send({
    url: Api.UpdatePin,
    method: "POST",
    data: params,
  });
};

export const updateSn = (params: { id: string; sn: string }) => {
  return Request.getInstance().send({
    url: Api.UpdateSn,
    method: "POST",
    data: params,
  });
};

export const addRepairParts = (params: any) => {
  return Request.getInstance().send({
    url: Api.AddRepairParts,
    method: "POST",
    data: params,
  });
};

export const updateRepairParts = (params: any) => {
  return Request.getInstance().send({
    url: Api.UpdateRepairParts,
    method: "POST",
    data: params,
  });
};

export const removeRepairParts = (params: any) => {
  return Request.getInstance().send({
    url: Api.RemoveRepairParts,
    method: "POST",
    data: params,
  });
};
